package com.spzx.order.controller;

import com.github.pagehelper.PageHelper;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.order.domain.OrderInfo;
import com.spzx.order.form.OrderForm;
import com.spzx.order.service.IOrderInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.service.GenericParameterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author Login
 * @since 2025-07-27
 */
@Tag(name = "订单管理")
@RestController
@RequestMapping("/orderInfo")
public class OrderInfoController extends BaseController {
    @Autowired
    private IOrderInfoService orderInfoService;
    private GenericParameterService parameterBuilder;

    @Operation(summary = "订单结算")
    @GetMapping("/trade")
    public AjaxResult orderTradeData(){
        return success(orderInfoService.orderTradeData());
    }
    @Operation(summary = "用户提交订单")
    @PostMapping("/submitOrder")
    public AjaxResult submitOrder(@RequestBody OrderForm orderForm){
        return success(orderInfoService.submitOrder(orderForm));
    }
    @Operation(summary = "立即购买")
    @GetMapping("/buy/{skuId}")
    public AjaxResult buy(@PathVariable Long skuId){
        return success(orderInfoService.buy(skuId));
    }

    @Operation(summary = "获取订单信息")
    @GetMapping("/getOrderInfo/{orderId}")
    public AjaxResult getOrderInfo(@PathVariable Long orderId){
        return success(orderInfoService.getOrderInfoById(orderId));
    }

    @Operation(summary = "获取用户订单分页列表")
    @GetMapping("/userOrderInfoList/{pageNum}/{pageSize}")
    public TableDataInfo list(
            @Parameter(name = "pageNum", description = "当前页码", required = true)
            @PathVariable Integer pageNum,

            @Parameter(name = "pageSize", description = "每页记录数", required = true)
            @PathVariable Integer pageSize,

            @Parameter(name = "orderStatus", description = "订单状态", required = false)
            @RequestParam(required = false, defaultValue = "") Integer orderStatus
    ){
        PageHelper.startPage(pageNum,pageSize);
        List<OrderInfo> list = orderInfoService.selectUserOrderInfoList(orderStatus);
        return getDataTable(list);
    }

    @Operation(summary = "取消订单")
    @GetMapping("/cancelOrder/{orderId}")
    public AjaxResult cancelOrder(@PathVariable Long orderId){
        orderInfoService.cancelOrder(orderId);
        return success();
    }




}
